<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/html">
<head>
    <meta charset="UTF-8">
    <title>学生签到界面</title>
    <link href="https://www.layuicdn.com/layui/css/layui.css" rel="stylesheet" type="text/css"/>
    <!-- 引入layui js -->
    <script src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
    <script src="https://www.layuicdn.com/layui/layui.js"></script>
    <link href="../css/Sign_Rob.css" rel="stylesheet">
</head>
<body>
<div id="box">
    <h2 id="title">输入学号和名字</h2>
    <form class="layui-form" id="forms" lay-filter="example">
        <input class="layui-input" id="stuid" lay-verify="stuid" name="stuid" placeholder="请输入学号"
               autofocus="autofocus">
        <input class="layui-input" id="name" lay-verify="username" name="stuname" placeholder="请输入姓名">
        <input id="btn" type="button" value="提交"/>
    </form>
</div>

<script>
    $('input').eq(2).click(() => {
        const stuid = String(document.getElementById("stuid").value);
        const name = String(document.getElementById("name").value);
        let currentUrl = window.location.href;
        let url = new URL(currentUrl);
        let timeStamp = url.searchParams.get("timeStamp");
        if (Date.now() - timeStamp > 15 * 1000) {
            alert('二维码已失效，请重新扫码!');
        } else {
            $.ajax({
                type: "get",
                url: "/sign/sign",
                data: {"name": name, "stuid": stuid, "type": 2},
                async: true,
                success: (result) => {
                    if (result.status) {
                        alert(result.message);
                    } else {
                        alert(result.message);
                    }
                }
            })
        }
    })
</script>
</body>
</html>